package cn.wolfcode.trip.app.controller;

import cn.wolfcode.trip.base.domain.StrategyCommentLike;
import cn.wolfcode.trip.base.service.IStrategyCommentLikeService;
import cn.wolfcode.trip.base.service.IStrategyLikeService;
import cn.wolfcode.trip.base.util.JSONResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 给攻略点评的点赞的接口
 */
@RestController
@RequestMapping("strategyCommentLike")
public class StrategyCommentLikeController {

    @Autowired
    private IStrategyCommentLikeService strategyCommentLikeService;
    @Autowired
    private IStrategyLikeService strategyLikeService;

    /**
     * 用户给某条评论点赞
     * @param commentLike
     */
    @PostMapping("add")
    public JSONResult addLike(StrategyCommentLike commentLike){
        commentLike.setStatus(StrategyCommentLike.STATUS_LIKE);
        strategyCommentLikeService.save(commentLike);
        return new JSONResult();
    }

    /**
     * 某用户取消对某条评论的点赞(删除该条记录)
     * @param commentLike
     * @return
     */
    @PostMapping("delete")
    public JSONResult delete(StrategyCommentLike commentLike){
        strategyCommentLikeService.delete(commentLike);
        return new JSONResult();
    }


    /**
     * 统计某条攻略评论的点赞数
     * @param commentId
     * @return
     */
    @GetMapping("countNum")
    public int countNumByCommentId(Long commentId){
        int num = strategyCommentLikeService.countNumByCommentId(commentId);
        return num;
    }

    /**
     * 查看某用户对某条攻略评论的点赞状态(是否对该评论点赞)
     * @param commentLike
     * @return
     */
    @GetMapping("getStatus")
    public int getStatus(StrategyCommentLike commentLike){
        int status = strategyCommentLikeService.getStatusByLikerId(commentLike);
        return status;
    }

    @GetMapping("getAllStatusByLikerId")
    public List getAllStatusByLikerId(Long likerId){
        List<Long> commentIds =  strategyCommentLikeService.getAllStatusByLikerId(likerId);
        return commentIds;
    }

    /**
     * 统计某条大攻略被点赞的次数
     * @param strategyId
     * @return
     */
    @GetMapping("getStrategyLikeByStrategyId")
    public int getStrategyLikeByStrategyId(Long strategyId){
        int count = strategyLikeService.getStrategyLikeCountByStrateId(strategyId);
        return count;
    }
}
